export default {
  data() {
    return {
      syncDetailModal: {
        theadsInfo: [
          { index: 0, isShow: false, prop: 'parkName', text: '支持停车场', minWidth: 120 },
          { index: 1, isShow: false, prop: 'customVipName', text: '绑定VIP类型', minWidth: 120 },
          { index: 2, isShow: false, prop: 'sendTime', text: '同步时间', minWidth: 170 },
          { index: 3, isShow: false, prop: 'sendStatus', text: '同步结果', minWidth: 120 },
          { index: 4, isShow: false, prop: 'respDesc', text: '失败原因', minWidth: 120 },
          { index: 5, isShow: false, prop: 'operate', text: '操作', minWidth: 120 },
        ],
        syncDetailList: []
      },
    }
  },
  created() {
    // this.getList();
  },
  filters: {
    sendStatus: function (val) {
      switch (val) {
        case 'UNSEND':
          return '未发送'
        case 'SENDING':
          return '发送中'
        case 'FAILED':
          return '同步失败'
        case 'SUCCEED':
          return '同步成功'
        default:
          break;

      }
    }
  },
  methods: {
    getList() {
      let params = $.extend({}, this.searchParams, this.otherParams);
      if(params.hasOwnProperty("query_carCode")){
        delete params.query_carCode
        let attribStr = this.searchList[2].value
        params[attribStr] = this.searchList[2].inputVal
      }
      this.getBillDetailList(params);
    },
    getBillDetailList(aparams) {
      let self = this,
        params = {
          page: this.pageNumber,
          rp: this.pageSize
        };
      params = $.extend({}, params, aparams);
      API.monthTicket.billDetailList(params)
        .then(res => {
          let data = res.data,
            list = data.rows;
          self.tbodysInfo = list;
          self.total = data.total;
        }, err => { })
    },
    exportData() {
      let self = this;
      let theadsArr = []
      for(let i = 0; i<self.theadsInfo.length; i++){
        if(self.theadsInfo[i].checked){
          theadsArr.push(self.theadsInfo[i].prop)
        }
      }
      let params = {
        meterList: theadsArr.join(',')
      };
      params = $.extend({}, params, this.searchParams, this.otherParams);
      if(params.hasOwnProperty("query_carCode")){
        delete params.query_carCode
        let attribStr = this.searchList[2].value
        params[attribStr] = this.searchList[2].inputVal
      }
      this.toExportAsync('monthTicketBill/detail/export.do', params);
    },
    syncDetail(monthTicketBillDetailId, open) {
      var self = this;
      let params = {
        monthTicketBillDetailId: monthTicketBillDetailId
      };
      API.monthTicket.billDetailSyncDetailList(params)
        .then(res => {
          let data = res.data;
          self.syncDetailModal.syncDetailList = data;
          if (open) {
            self.toOpenModal('syncDetailModal');
          }
        }, err => { })
    },
    reSync(syncDetail) {
      var self = this;
      let params = {
        id: syncDetail.id
      };
      API.monthTicket.billDetailReSync(params)
        .then(res => {
          self.syncDetail(syncDetail.monthTicketBillDetailId);
          self.showToast('重新同步成功', false);
        }, err => { })

    },
    copyLink(obj) {
      let self=this;
      let ifx = 2;//标识aomp开票
      let openInvoiceUrl = obj.openUrlInvoice;
      let billCode = obj.billCode;
      let parkCode = obj.parkCode;
      let link = openInvoiceUrl + "?if=" + ifx + "&pc=" + parkCode + "&bc=" + billCode;
      //console.log(link);
      var aux = document.createElement("input");
      var content = link;
      aux.setAttribute("value", content);
      document.body.appendChild(aux);
      aux.select();
      document.execCommand("copy");
      document.body.removeChild(aux);
      self.showToast("复制链接成功", 1, 1500);
    }
  }
}